package com.example.zsf.activity.account;

import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.blankj.utilcode.util.SPUtils;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.example.zsf.R;
import com.example.zsf.adapter.AvatarListAdapter;
import com.example.zsf.utils.DebouncedOnItemClickListener;
import com.example.zsf.view.NavigationBar;

import java.util.Arrays;

import butterknife.BindView;
import butterknife.ButterKnife;

public class AvatarSelectListActivity extends AppCompatActivity {
    @BindView(R.id.navigationBar)
    NavigationBar navigationBar;
    @BindView(R.id.recyclerView)
    RecyclerView recyclerView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_avatar_select_list);
        ButterKnife.bind(this);

        initUI();
    }

    private void initUI() {

        Window window = getWindow();
        View decorView = window.getDecorView();
        int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
        decorView.setSystemUiVisibility(option);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(Color.TRANSPARENT);
        }


        navigationBar.setTitleText("头像选择");
        navigationBar.setLeftWhite();
        navigationBar.setLeftClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                finish();
            }
        });


        AvatarListAdapter adapter = new AvatarListAdapter(R.layout.item_avatar, Arrays.asList(
                R.mipmap.zhanshi,
                R.mipmap.nvzhanshi,
                R.mipmap.fashi,
                R.mipmap.nvfashi,
                R.mipmap.daoshi,
                R.mipmap.nvdaoshi));
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(adapter);
        adapter.setOnItemClickListener(new DebouncedOnItemClickListener(400) {
            @Override
            public void onDebouncedItemClick(@NonNull BaseQuickAdapter<?, ?> adapter, @NonNull View view, int position) {
                SPUtils.getInstance().put("avatar",position);
                Intent intent = new Intent();
                intent.putExtra("selected", position);
                setResult(RESULT_OK, intent);
                finish();
            }
        });
    }
}